package main

import (
	_ "embed"
	"encoding/json"
	"os"
	"strings"
)

//go:embed zh.json
var zh []byte

//go:embed en.json
var en []byte

var TData map[string]interface{}

func init() {
	TData = make(map[string]interface{})

	lang := os.Getenv("LANG")
	if lang == "" || strings.HasPrefix(lang, "zh_") {
		err := json.Unmarshal(zh, &TData)
		if err != nil {
			panic(err)
		}
	} else {
		err := json.Unmarshal(en, &TData)
		if err != nil {
			panic(err)
		}
	}
}

func T(s string) string {
	v, ok := TData[s]
	if ok {
		return v.(string)
	}
	return s
}
